package a.f;

import a.c.bb;
import a.c.*;
import a.c.w;
import a.c.x;
import a.f.c.h;
import a.i.db;
import a.i.l;
import a.i.wb;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class ld
{
  public static final byte a = 0;
  public static final byte b = 1;
  public static final byte c = 2;
  private static final int d = 10;
  private static final int e = 1;
  public static boolean f;
  
  public static void a(q paramq, k paramk)
  {
    a(paramq, paramk, 5, 2);
  }
  
  public static void a(q paramq, k paramk, int paramInt1, int paramInt2)
  {
    boolean bool = o.eg;
    int n = o.dg;
    if ((paramq == null) || (paramk == null)) {
      return;
    }
    q localq = new q();
    n localn = localq.C();
    x localx1 = localq.B();
    a(localq, localn, paramq, paramk, localx1, paramInt2);
    int[] arrayOfInt1 = new int[localq.k()];
    int[] arrayOfInt2 = new int[localq.k()];
    double d1 = 1.7976931348623157E+308D;
    wb localwb = new wb(7L);
    x localx2 = db.a(new boolean[localq.k()]);
    bb localbb1 = new bb();
    bb localbb2 = new bb();
    Object localObject1 = localq.v();
    label218:
    do
    {
      if (!((w)localObject1).e()) {
        break;
      }
      localObject2 = ((w)localObject1).d();
      localObject3 = (b_)localx1.get(localObject2);
      if (!bool) {
        if (((b_)localObject3).b())
        {
          localbb1.add(localObject2);
          localx2.a(localObject2, false);
          if (bool) {
            continue;
          }
          if (n == 0) {
            break label218;
          }
        }
      }
      localbb2.add(localObject2);
      localx2.a(localObject2, true);
      ((w)localObject1).f();
    } while (n == 0);
    localObject1 = localbb1.p();
    Object localObject2 = localbb2.p();
    Object localObject3 = localx1;
    Comparator local0 = new Comparator()
    {
      private final x val$swimNode2Swimlane;
      
      public int compare(Object paramAnonymousObject1, Object paramAnonymousObject2)
      {
        boolean bool = o.eg;
        ld.b_ localb_1 = (ld.b_)this.val$swimNode2Swimlane.get(paramAnonymousObject1);
        ld.b_ localb_2 = (ld.b_)this.val$swimNode2Swimlane.get(paramAnonymousObject2);
        if (!bool)
        {
          if (localb_1.a() > localb_2.a()) {
            return 1;
          }
          if (bool) {}
        }
        else if (localb_1.a() < localb_2.a())
        {
          return -1;
        }
        return 0;
      }
    };
    l.a((Object[])localObject2, local0);
    e[] arrayOfe = a((e[])localObject1, (e[])localObject2, localwb);
    int i = 0;
    label328:
    label347:
    label350:
    label508:
    do
    {
      if (i >= paramInt1) {
        break;
      }
      int j = 0;
      do
      {
        if (j >= arrayOfe.length) {
          break label328;
        }
        arrayOfInt1[arrayOfe[j].f()] = j;
        j++;
        if ((!bool) && (n != 0)) {
          break;
        }
      } while (n == 0);
      if (bool) {
        break label608;
      }
      double d2 = a(localq, localn, arrayOfInt1);
      int k = 0;
      int m = 1;
      do
      {
        do
        {
          if (m < arrayOfe.length) {}
          while (bool)
          {
            if (n == 0)
            {
              if (localx2.getBool(arrayOfe[(m - 1)]))
              {
                if (bool) {
                  break label508;
                }
                if (localx2.getBool(arrayOfe[m])) {}
              }
              else
              {
                double d3 = a(arrayOfe[(m - 1)], arrayOfe[m], arrayOfInt1, localn);
                if (bool) {
                  break label508;
                }
                if (d3 < 0.0D)
                {
                  arrayOfInt1[arrayOfe[(m - 1)].f()] += 1;
                  arrayOfInt1[arrayOfe[m].f()] -= 1;
                  e locale2 = arrayOfe[(m - 1)];
                  arrayOfe[(m - 1)] = arrayOfe[m];
                  arrayOfe[m] = locale2;
                  d2 += d3;
                  k = 1;
                }
              }
              m++;
              if (n == 0) {
                break label350;
              }
              if (bool) {
                break label347;
              }
            }
            if (k != 0) {
              break;
            }
          }
        } while (n != 0);
        if (d1 <= d2) {
          break label587;
        }
        m = 0;
        do
        {
          if (m >= arrayOfInt1.length) {
            break;
          }
          arrayOfInt2[m] = arrayOfInt1[m];
          m++;
          if (bool) {
            break label603;
          }
          if (n != 0) {
            break label601;
          }
        } while (n == 0);
      } while (bool);
      d1 = d2;
      arrayOfe = a((e[])localObject1, (e[])localObject2, localwb);
      i++;
    } while (n == 0);
    label587:
    label601:
    label603:
    label608:
    w localw = localq.v();
    do
    {
      if (!localw.e()) {
        break;
      }
      e locale1 = localw.d();
      b_ localb_ = (b_)localx1.get(locale1);
      localb_.a(arrayOfInt2[locale1.f()]);
      localw.f();
      if ((!bool) && (n != 0)) {
        return;
      }
    } while (n == 0);
    localq.a(localx1);
    localq.a(localn);
    if (!bool) {
      localq.o();
    }
  }
  
  private static e[] a(e[] paramArrayOfe1, e[] paramArrayOfe2, wb paramwb)
  {
    boolean bool = o.eg;
    int n = o.dg;
    paramwb.a(paramArrayOfe1);
    e[] arrayOfe = new e[paramArrayOfe1.length + paramArrayOfe2.length];
    int i = 0;
    int j = 0;
    int k = 0;
    label109:
    do
    {
      if (k >= arrayOfe.length) {
        break;
      }
      if (n != 0) {
        break label118;
      }
      int m = paramArrayOfe1.length - i + paramArrayOfe2.length - j;
      if (!bool)
      {
        if (paramwb.nextInt(m) < paramArrayOfe1.length - i) {
          arrayOfe[k] = paramArrayOfe1[(i++)];
        }
      }
      else
      {
        if (bool) {
          continue;
        }
        if (n == 0) {
          break label109;
        }
      }
      arrayOfe[k] = paramArrayOfe2[(j++)];
      k++;
    } while (n == 0);
    label118:
    return arrayOfe;
  }
  
  private static void a(q paramq1, n paramn, q paramq2, k paramk, x paramx, int paramInt)
  {
    boolean bool = o.eg;
    int i = o.dg;
    HashMap localHashMap = new HashMap();
    Object localObject1 = paramq2.v();
    do
    {
      do
      {
        if (!((w)localObject1).e()) {
          break;
        }
        e locale1 = ((w)localObject1).d();
        Object localObject2 = paramk.get(locale1);
        if (!bool)
        {
          if (localObject2 != null)
          {
            if (bool) {
              continue;
            }
            if (!localHashMap.containsKey(localObject2))
            {
              e locale2 = paramq1.i();
              localHashMap.put(localObject2, locale2);
              paramx.a(locale2, localObject2);
            }
          }
          ((w)localObject1).f();
        }
      } while (i == 0);
    } while (bool);
    localObject1 = new d[paramq1.k()][paramq1.k()];
    if (!bool)
    {
      if (paramInt != 1) {
        if (bool) {
          break label176;
        }
      }
    }
    else {
      if (paramInt != 2) {
        break label174;
      }
    }
    c(paramq2, paramq1, paramk, localHashMap, paramn, (d[][])localObject1);
    label174:
    label176:
    if (((!bool) && (paramInt == 0)) || (paramInt == 2)) {
      a(paramq2, paramq1, paramk, localHashMap, paramn, (d[][])localObject1);
    }
  }
  
  private static void a(q paramq1, q paramq2, k paramk, Map paramMap, n paramn, d[][] paramArrayOfd)
  {
    boolean bool = o.eg;
    int m = o.dg;
    e[] arrayOfe = paramq2.t();
    m localm = paramq1.w();
    label251:
    do
    {
      if (!localm.e()) {
        break;
      }
      d locald1 = localm.a();
      Object localObject1 = paramk.get(locald1.e());
      Object localObject2 = paramk.get(locald1.f());
      if (!bool)
      {
        if ((localObject1 != null) && ((bool) || (localObject2 != null)))
        {
          e locale1 = (e)paramMap.get(localObject1);
          e locale2 = (e)paramMap.get(localObject2);
          if (bool) {
            continue;
          }
          if (locale1 != locale2)
          {
            int i = Math.min(locale1.f(), locale2.f());
            int j = Math.max(locale1.f(), locale2.f());
            if (!bool) {
              if (paramArrayOfd[i][j] == null)
              {
                locald2 = paramq2.a(arrayOfe[i], arrayOfe[j]);
                paramArrayOfd[i][j] = locald2;
                paramn.a(locald2, 1);
                if (bool) {
                  continue;
                }
                if (m == 0) {
                  break label251;
                }
              }
            }
            d locald2 = paramArrayOfd[i][j];
            int k = paramn.getInt(locald2);
            paramn.a(locald2, k + 1);
          }
        }
        localm.f();
      }
    } while (m == 0);
  }
  
  private static void c(q paramq1, q paramq2, k paramk, Map paramMap, n paramn, d[][] paramArrayOfd)
  {
    boolean bool = o.eg;
    int m = o.dg;
    if (!h.b(paramq1)) {
      return;
    }
    h localh = new h(paramq1);
    x localx = paramq2.B();
    w localw1 = paramq1.v();
    label214:
    do
    {
      do
      {
        if (!localw1.e()) {
          break label533;
        }
        bb localbb;
        do
        {
          e locale1 = localw1.d();
          if ((!bool) && (m != 0)) {
            return;
          }
          if (!localh.e(locale1)) {
            break label516;
          }
          localbb = new bb();
          Object localObject1 = localh.d(locale1).l();
          Object localObject2;
          do
          {
            if (!((w)localObject1).e()) {
              break label214;
            }
            e locale2 = ((w)localObject1).d();
            if (m != 0) {
              break;
            }
            if (!localh.e(locale2))
            {
              localObject2 = paramk.get(locale2);
              if (bool) {
                continue;
              }
              if (localObject2 != null)
              {
                e locale3 = (e)paramMap.get(localObject2);
                if (bool) {
                  continue;
                }
                if (!localx.getBool(locale3))
                {
                  localbb.add(locale3);
                  localx.a(locale3, true);
                }
              }
            }
            ((w)localObject1).f();
          } while (m == 0);
          localObject1 = localbb.p();
          if (bool) {
            break;
          }
          int i = 0;
          do
          {
            if (i >= localObject1.length - 1) {
              break label457;
            }
            localObject2 = localObject1[i];
            if (m != 0) {
              break;
            }
            int j = i + 1;
            do
            {
              do
              {
                if (j >= localObject1.length) {
                  break label444;
                }
                Object localObject3 = localObject1[j];
                if (m != 0) {
                  break;
                }
                Object localObject4 = localObject2.f() < localObject3.f() ? localObject2 : localObject3;
                if (!bool) {}
                Object localObject5 = localObject2.f() < localObject3.f() ? localObject3 : localObject2;
                if (!bool) {
                  if (paramArrayOfd[localObject4.f()][localObject5.f()] == null)
                  {
                    locald = paramq2.a(localObject4, localObject5);
                    paramArrayOfd[localObject4.f()][localObject5.f()] = locald;
                    paramn.a(locald, 10);
                    if (bool) {
                      continue;
                    }
                    if (m == 0) {
                      break label436;
                    }
                  }
                }
                d locald = paramArrayOfd[localObject4.f()][localObject5.f()];
                int k = paramn.getInt(locald);
                paramn.a(locald, k + 10);
                j++;
              } while (m == 0);
              i++;
            } while (bool);
          } while (m == 0);
        } while (bool);
        w localw2 = localbb.l();
        do
        {
          if (!localw2.e()) {
            break;
          }
          localx.a(localw2.d(), false);
          localw2.f();
          if (bool) {
            break label530;
          }
          if (m != 0) {
            break label528;
          }
        } while (m == 0);
      } while (bool);
      localw1.f();
    } while (m == 0);
    label436:
    label444:
    label457:
    if (!bool) {
      paramq2.a(localx);
    }
    label516:
    label528:
    label530:
    label533:
    return;
  }
  
  private static double a(e parame1, e parame2, int[] paramArrayOfInt, k paramk)
  {
    boolean bool = o.eg;
    int n = o.dg;
    int i = 0;
    int j = paramArrayOfInt[parame1.f()];
    int k = paramArrayOfInt[parame2.f()];
    m localm = parame1.l();
    d locald;
    int m;
    do
    {
      do
      {
        if (!localm.e()) {
          break;
        }
        locald = localm.a();
        m = paramArrayOfInt[locald.a(parame1).f()];
        if (n != 0) {
          break label177;
        }
        if (m != k) {
          i = (int)(i + paramk.getInt(locald) * (a(j + 1, m) - a(j, m)));
        }
        localm.f();
      } while (n == 0);
    } while (bool);
    localm = parame2.l();
    label177:
    do
    {
      if (!localm.e()) {
        break;
      }
      locald = localm.a();
      m = paramArrayOfInt[locald.a(parame2).f()];
      if (n != 0) {
        break label228;
      }
      if (m != j) {
        i = (int)(i + paramk.getInt(locald) * (a(k - 1, m) - a(k, m)));
      }
      localm.f();
    } while (n == 0);
    label228:
    return i;
  }
  
  private static double a(q paramq, k paramk, int[] paramArrayOfInt)
  {
    boolean bool = o.eg;
    int k = o.dg;
    double d1 = 0.0D;
    w localw = paramq.v();
    label138:
    label140:
    do
    {
      do
      {
        if (!localw.e()) {
          return d1;
        }
        e locale = localw.d();
        int i = paramArrayOfInt[locale.f()];
        m localm = locale.n();
        do
        {
          if (!localm.e()) {
            break;
          }
          d locald = localm.a();
          int j = paramArrayOfInt[locald.f().f()];
          d1 += paramk.getInt(locald) * a(i, j);
          localm.f();
          if (bool) {
            break label140;
          }
          if (k != 0) {
            break label138;
          }
        } while (k == 0);
      } while (bool);
      localw.f();
    } while (k == 0);
    return d1;
  }
  
  private static double a(int paramInt1, int paramInt2)
  {
    return Math.pow(Math.abs(paramInt1 - paramInt2), 2.0D);
  }
  
  public static class b_
  {
    private int a;
    private boolean c;
    public static boolean d;
    
    public b_(int paramInt, boolean paramBoolean)
    {
      this.a = paramInt;
      this.c = paramBoolean;
    }
    
    public int a()
    {
      return this.a;
    }
    
    public void a(int paramInt)
    {
      this.a = paramInt;
    }
    
    public boolean b()
    {
      return this.c;
    }
    
    public void a(boolean paramBoolean)
    {
      this.c = paramBoolean;
    }
  }
}



/* Location:           E:\idea\

 * Qualified Name:     a.f.ld

 * JD-Core Version:    0.7.0.1

 */